package com.huika.dealontop.control.base.extend;

import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.GridView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseAct;

/**
 * Author: Victor Wu
 * Email: victor-wu*foxmail.com
 * Time: 2015/11/12 12:11
 * Description: 带自定义标题栏的Activity
 */
public abstract class BaseActionBarActivity extends BaseAct {
    /**
     * activity 跟布局（包含标题栏）
     */
    protected ViewGroup mRootView;
    /**
     * activity 内容区（不包含标题栏）
     */
    protected FrameLayout mContentView;
    /**
     * 标题栏帮助
     */
    private ActionBarHelper mActionBarHelper;

    @Override
    public void setContentView(int layoutResID) {
        this.setContentView(View.inflate(this, layoutResID, null));
    }

    @Override
    public void setContentView(View view) {
        this.setContentView(view, null);
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        mRootView = (ViewGroup) View.inflate(this, R.layout.activity_action_bar, null);
        mContentView = (FrameLayout) mRootView.findViewById(R.id.content_area);
        if(params == null){
            mContentView.addView(view);
        }else{
            mContentView.addView(view, params);
        }
        super.setContentView(mRootView);
    }

    protected ActionBarHelper getActionBarHelper() {
        if (mActionBarHelper == null) {
            mActionBarHelper = new ActionBarHelper(mRootView);
            mActionBarHelper.setOnLeftClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
        }
        return mActionBarHelper;
    }

}
